﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProjectSheduleAnalyst
{
    public partial class LessonCreationAssistForm : Form
    {
        public LessonCreationAssistForm()
        {
            InitializeComponent();
            this.Text = "Выберите требуемую запись";
        }

        private DB_Access dba = new DB_Access();

        private void CloseLCAFButton_Click(object sender, EventArgs e)
        {
            Close();
        }
        
        private void LessonCreationAssistForm_Load(object sender, EventArgs e)
        {
            switch (Data.Status)
            {
                case 1:
                    {
                        DataSet ds3 = dba.FillGrid("SelectAllSubjects", "Subjects");
                        dgvLesCrAssForm.DataSource = ds3.Tables["Subjects"].DefaultView;
                        dgvLesCrAssForm.Columns[0].Visible = false;
                        dgvLesCrAssForm.Columns[1].HeaderText = "Название предмета";
                        break;
                    }
                case 2:
                    {
                        DataSet ds1 = dba.FillGrid("SelectAllTeachers", "Teachers");
                        dgvLesCrAssForm.DataSource = ds1.Tables["Teachers"].DefaultView;
                        dgvLesCrAssForm.Columns[0].Visible = false;

                        dgvLesCrAssForm.Columns[1].HeaderText = "Фамилия";
                        dgvLesCrAssForm.Columns[2].HeaderText = "Имя";
                        dgvLesCrAssForm.Columns[3].HeaderText = "Отчество";
                        dgvLesCrAssForm.Columns[4].HeaderText = "Кафедра";   
                        break;
                    }
                case 3:
                    {
                        DataSet ds2 = dba.FillGrid("SelectAllGroups", "Groups");
                        dgvLesCrAssForm.DataSource = ds2.Tables["Groups"].DefaultView;
                        dgvLesCrAssForm.Columns[0].Visible = false;

                        dgvLesCrAssForm.Columns[1].HeaderText = "Курс";
                        dgvLesCrAssForm.Columns[2].HeaderText = "Специальность";
                        dgvLesCrAssForm.Columns[3].HeaderText = "Группа";
                        dgvLesCrAssForm.Columns[4].HeaderText = "Подгруппа";
                        break;
                    }
                case 4:
                    {
                        DataSet ds4 = dba.FillGrid("SelectAllClassRoomTypes", "ClassRoomTypes");
                        dgvLesCrAssForm.DataSource = ds4.Tables["ClassRoomTypes"].DefaultView;
                        dgvLesCrAssForm.Columns[0].Visible = false;

                        dgvLesCrAssForm.Columns[1].HeaderText = "Тип";
                        break;
                    }

            }
        }

        private void dgvLesCrAssForm_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void AddChosenRowLCAFButton_Click(object sender, EventArgs e)
        {
            ActionChoosing();
        }

        public void ActionChoosing()
        {
            LessonCreationForm LesCrForm = this.Owner as LessonCreationForm;
            switch (Data.Status)
            {
                case 1:
                    {
                        LesCrForm.SubjectTextBox.Text = dgvLesCrAssForm.CurrentRow.Cells[1].Value.ToString();
                        LesCrForm.IDlist.Add(dgvLesCrAssForm.CurrentRow.Cells[0].Value.ToString());
                        //LesCr.txtbLesCrTeacher.Text = dgvLesCrAsF.CurrentRow.Cells[1].Value.ToString() + " " + dgvLesCrAsF.CurrentRow.Cells[2].Value.ToString() + " " + dgvLesCrAsF.CurrentRow.Cells[3].Value.ToString();
                        //TeacherID = dgvLesCrAsF.CurrentRow.Cells[0].Value.ToString();
                        ////LesCr.txtbLesCrTeacher.Text = dgvLesCrAsF.CurrentRow.Cells[0].Value.ToString();
                        //LesCr.label4.Text = TeacherID;
                        this.Close();
                        break;
                    }
                case 2:
                    {
                        string s = dgvLesCrAssForm.CurrentRow.Cells[1].Value.ToString();
                        string n = dgvLesCrAssForm.CurrentRow.Cells[2].Value.ToString();
                        string p = dgvLesCrAssForm.CurrentRow.Cells[3].Value.ToString();

                        LesCrForm.TeacherTextBox.Text = s + " " + n + " " + p;
                        LesCrForm.IDlist.Add(dgvLesCrAssForm.CurrentRow.Cells[0].Value.ToString());
                        this.Close();
                        break;
                    }
                case 3:
                    {
                        string c = dgvLesCrAssForm.CurrentRow.Cells[1].Value.ToString();
                        string g = dgvLesCrAssForm.CurrentRow.Cells[3].Value.ToString();
                        string sg = dgvLesCrAssForm.CurrentRow.Cells[4].Value.ToString();

                        LesCrForm.GroupTextBox.Text = "Курс: " + c + " " + "Группа: " + g + " " + "Подгруппа: " + sg;
                        LesCrForm.IDlist.Add(dgvLesCrAssForm.CurrentRow.Cells[0].Value.ToString());
                        this.Close();
                        break;
                    }
                case 4:
                    {
                        LesCrForm.ClassTextBox.Text = dgvLesCrAssForm.CurrentRow.Cells[1].Value.ToString();
                        LesCrForm.IDlist.Add(dgvLesCrAssForm.CurrentRow.Cells[0].Value.ToString());
                        this.Close();
                        break;
                    }
            }
        }

        private void dgvLesCrAssForm_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            ActionChoosing();
            this.DialogResult = DialogResult.OK;
        }
    }
}
